package com.example.teaching_server.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.*;
import org.hibernate.annotations.CreationTimestamp;
import java.time.LocalDateTime;

/**
 * 教师工具实体类
 */
@Getter
@Setter
@ToString
@EqualsAndHashCode(of = "id")
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "teacher_tools", indexes = {
        @Index(name = "idx_tool_sort", columnList = "sort_order"),
        @Index(name = "idx_tool_active", columnList = "is_active")
})
public class TeacherTool {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotBlank(message = "工具名称不能为空")
    @Size(max = 100, message = "工具名称长度不能超过100个字符")
    @Column(nullable = false, length = 100)
    private String name;

    @NotBlank(message = "工具图标不能为空")
    @Size(max = 50, message = "工具图标长度不能超过50个字符")
    @Column(nullable = false, length = 50)
    private String icon;

    @Size(max = 200, message = "路由路径长度不能超过200个字符")
    @Column(name = "route_path", length = 200)
    private String routePath;

    @Builder.Default
    @Column(name = "sort_order")
    private Integer sortOrder = 0;

    @Builder.Default
    @Column(name = "is_active")
    private Boolean isActive = true;

    @CreationTimestamp
    @Column(name = "created_at", updatable = false)
    private LocalDateTime createdAt;

    // 移除新增字段，或者更新数据库表结构
    // @Size(max = 500, message = "工具描述长度不能超过500个字符")
    // @Column(name = "description", length = 500)
    // private String description;

    // @Size(max = 100, message = "权限要求长度不能超过100个字符")
    // @Column(name = "permission_required", length = 100)
    // private String permissionRequired;

    public boolean isValid() {
        return name != null && !name.trim().isEmpty() &&
                icon != null && !icon.trim().isEmpty();
    }

    public boolean isAvailable() {
        return Boolean.TRUE.equals(isActive);
    }
}
